# DjangoDE, an integrated development environment for Django
# Copyright (C) 2010-2011 Andrew Wilkinson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import sys
import unittest

from djangode import global_objects
from djangode.gui import MainWindow
from djangode.utils.qt import Qt, QtCore, QtGui

class TestMainWindow(unittest.TestCase):
    def setUp(self):
        if hasattr(sys, "last_type"):
            del sys.last_type

        global_objects.main_window = MainWindow()
        global_objects.main_window.show()

    def tearDown(self):
        global_objects.main_window.close()
        global_objects.main_window = None

    def test_focus_on_new_editor(self):
        """
        Test that when you create a new editor tab that it has focus.
        """
        global_objects.main_window.actions["new_file"].trigger()
        editor = global_objects.main_window.editor.widget(0)
        global_objects.app.processEvents()

        self.assert_(editor.hasFocus())
